import OperationLogDialog from './operation-log-dialog.vue'
import zhCn from "element-plus/es/locale/lang/zh-cn";
import ElementPlus from 'element-plus'
import { createApp, h } from 'vue';
  import JsonViewer from "vue3-json-viewer"
  import "vue3-json-viewer/dist/index.css";

   
const openOperationLogDialog = (params) => {
  const container = document.createElement('div');
  document.body.appendChild(container);
  
  return new Promise((resolve) => {
    const app = createApp({
      render() {
        return h(OperationLogDialog, {
          ref: 'OperationLogDialogRef',
          onClose: () => {
            resolve(null)
            app.unmount()
            document.body.removeChild(container)
          }
        });
      }
    });
    app.use(ElementPlus, {locale: zhCn})
    app.use(JsonViewer)
    const instance = app.mount(container)
    const OperationLogDialogRef : InstanceType<typeof OperationLogDialog> = instance.$refs.OperationLogDialogRef
    OperationLogDialogRef.openDialog(params)
  });
}

export default openOperationLogDialog